const request = (options , isShowLoading = true) => {
  options.method && (options.method = options.method.toUpperCase());
  return new Promise((resolve, reject) => {
    if(isShowLoading){
      uni.showLoading({
        title: '加载中'
      })
    }
    const HOST = 'http://localhost:3000' // 自己的域名
    const url = `${HOST}${options.url}`
    uni.request({
      url ,
      method: options.method || "GET",
      data: options.data || {},
      header: options.header || {
        "content-type": "application/x-www-form-urlencoded",
      },
      success: (res) => {
        resolve(res.data);
      },
      fail: (err) => {
        reject(err);
      },
      complete:()=>{
        if(isShowLoading){
          uni.hideLoading()
        }
      }
    });
  });
};

export default request;
